package com.caiheng.api.service.active.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.caiheng.api.dao.active.CommunityActiveMapper;
import com.caiheng.api.entity.active.CommunityActive;
import com.caiheng.api.service.active.CommunityActiveService;
import com.caiheng.api.service.base.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 社区活动Service业务层处理
 *
 * @author ruoyi
 * @date 2023-12-26
 */
@Service
public class CommunityActiveServiceImpl extends BaseServiceImpl<CommunityActiveMapper, CommunityActive> implements CommunityActiveService {

    @Resource
    private CommunityActiveMapper activeMapper;

    @Value("${web.imgPrefix}")
    private String imgPrefix;//图片地址

    @Override
    public List<CommunityActive> getActivceList(int user_id, int active_type, int pageIndex, int pageSize) {
        QueryWrapper<CommunityActive> qw = new QueryWrapper<>();
        qw.eq("active_type", active_type);
        qw.eq("state", 1);
        qw.orderByDesc("begin_time");
        List<CommunityActive> actives = activeMapper.getPageEntityList(qw,pageIndex,pageSize);
        if(CollUtil.isNotEmpty(actives)){
            for (CommunityActive active : actives){
                if(StrUtil.isNotEmpty(active.getPreviewImg())){
                    active.setPreviewImg(imgPrefix + active.getPreviewImg());
                }
            }
        }
        return actives;
    }
}
